<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('药品列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                药品名称：<input type="text" name="name"/>
                            </li>
                            <li>
                                药品类型：<select name="typeId" th:with="type=${@dict.getType('sys_drug_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li class="select-time">
                                <label>上架时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                       name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                       name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:drug:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:pet:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:pet:remove')}]];
    var prefix = ctx + "system/drug";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryUserList();
    });

    function queryUserList() {
        var options = {
            url: prefix + "/list",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "药品列表",
            removeUrl: prefix + "/remove",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            columns: [{
                checkbox: true,
            },
                // {
                //     field: 'id',
                //     title: '宠物id',
                // },
                {
                    field: 'name',
                    title: '药名',
                },
                {
                    field: 'sysDrugType.typename',
                    title: '药品类型'
                },
                {
                    field:'dept',
                    title:'制药单位'
                },
                {
                    field:'validity',
                    title:'有效期'
                },
                {
                    field:'price',
                    title:'价格'
                },
                {
                    field:'effect',
                    title:'疗效'
                },
                {
                    field: 'del_flag',
                    title: '销售状态',
                    formatter: function (value, item, index) {
                        if(item.del_flag==='0'){
                            return '销售中';
                        }else {
                            return '已下架';
                        }
                    }
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
				{
                    field: 'createTime',
                    title: '上架时间',
                    sortable: true
                },
				{
                    field: 'updateBy',
                    title: '更新者'
                },
				{
                    field: 'updateTime',
                    title: '更新时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.del_flag === '0'){
                          actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>下架</a> ');
                        }
                        actions.push('<a class="btn btn-info btn-xs '  + '" href="javascript:void(0)" onclick="$.operate.showImage(\'' + row.id + '\')"><i class="fa fa-key"></i>药盒图片</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }


    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

</script>
</body>
</html>